#！/bin/bash
# openEuler 24.03-LTS版本安装docker-ce的脚本
# author：wqf , date: 2024-06-28
checkCode() {
    if [ $? -eq 0 ];then
        echo "返回状态码: $?,[$1]执行成功！"
    else
        echo "返回状态码：$?,[$1]执行异常，请检查！"
        echo "程序已退出"
        exit
    fi
}

installDocker() {
    #关闭防火墙
    systemctl stop firewalld
    systemctl disable firewalld

    #添加docker源
    dnf config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    checkCode "docker-ce源已添加"

    #替换repo版本
    repoPath="/etc/yum.repos.d"
    sed -i 's/\$releasever/8.9/g' $repoPath/docker-ce.repo

    #安装docker-ce
    dnf install -y docker-ce
    Ver=$(docker version | grep Version| awk -F: '{print $2}')
    checkCode "docker-ce-$Ver 已经安装"

    # 启动docker
    systemctl restart docker && systemctl  enable docker
}

imageConfig() {
    #配置镜像加速
    cat > /etc/docker/daemon.json << EOF
{
  "registry-mirrors": ["https://mirror.ccs.tencentyun.com"]
}
EOF
    systemctl daemon-reload && systemctl restart docker && systemctl status docker

}

# 执行安装
totalInstall() {
    installDocker
    imageConfig
}

totalInstall
